﻿<?php include("conn.php");
mysql_query('SET NAMES UTF8'); 
error_reporting(0);
	  

class MyPrizeBean {
	
	public $heading;
	public $name;
	public $images;
	public $title;
	public $addtime;
	public $reply;
	public $content;
	public $like;
	public $cid;
	public $isLike;
	public $role;
	public $userid;
	
	function __construct($heading,$name,$images,$title,$addtime,$reply,$content,$like,$cid,$isLike,$role,$userid) {
		$this->heading      = 	$heading;
		$this->name      	= 	$name;
		$this->images      	= 	$images;
		$this->title      	= 	$title;
		$this->addtime      = 	$addtime;
		$this->reply      	= 	$reply;
		$this->content      = 	$content;
		$this->like      	= 	$like;
		$this->cid      	= 	$cid;
		$this->isLike      	= 	$isLike;
		$this->role     	= 	$role;
		$this->userid		= 	$userid;
	}
}

if($_REQUEST['page']!="") {
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
} else {
	$de=0;
	$size=5;
}

$upfile = 'uploads';
if (!file_exists($upfile)) { 
        mkdir($upfile, 0777, true);
 }

$rert31 = mysql_query("select *from talks where  path ='".$_REQUEST[path]."' and cityid='".$_REQUEST[city]."' order by id desc limit $de,$size ");
$prize = array();

while($rowf = mysql_fetch_array($rert31)) {

	$de = array();//图片
	if($rowf[images]!="") {
	  $ime = $rowf[images];
	  $de  = explode("," ,$ime);
	}
				 //图片end

	$smallImg = array();
	if($rowf[thumbImages]!="") {
	      $ime = $rowf[thumbImages];
	      $smallImg = explode("," ,$ime);
	}

	//判断角色id,查询不同的数据表
/*	if($rowf['role'] == 1) {
		$table = 'users';
		$id = 'userid';
	} else {
		$table = 'shop';
		$id = 'shopid';
	}*/

	switch ($rowf['role']) {
		case 1:
			$table = 'user';
			$id = 'userid';
			$rert32 = mysql_query("select * from " . $table . " where " . $id . " = '" . $rowf[userid]."'");
			$rowf3 = mysql_fetch_array($rert32);
			break;
		
		case 2:
			$table = 'shop';
			$id = 'shopid';
			$rert32 = mysql_query("select * from " . $table . " where " . $id . " = '" . $rowf[userid]."'");
			$rowf3 = mysql_fetch_array($rert32);
			break;
	}

	if($rowf3['name']) {
		$rowf3['niname'] = $rowf3['name'];
	}

	 //评论判断
	 if($rowf['replymember']!=null) {
	 	$replymember = $rowf['replymember'];
	 }else{
	 	$replymember = '暂时无回复';
	 }

	 $rert33 = mysql_query("select * from talklike where userid='".$_REQUEST[userid]."' and talkid='".$rowf[id]."'" );
	 $rowf33 = mysql_fetch_array($rert33);

	 if ($rowf33 != false) {
	 	$isLike = 1;
	 } else {
	 	$isLike = 0;
	 }

	$prize[] = new MyPrizeBean($rowf3['images'],$rowf3['niname'],$smallImg,$rowf['title'],$rowf['addtime'],$replymember,$rowf['content'],$rowf['xihuan'],$rowf['id'],$isLike,$rowf['role'],$rowf['userid']);
		
}

echo json_encode($prize);




?>